/*
 * TOP SECRET Copyright 2006-2015 Transsion.com All right reserved. This software is the confidential and proprietary
 * information of Transsion.com ("Confidential Information"). You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license agreement you entered into with Transsion.com.
 */
package com.yunji.framework_template.biz.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Service;

import com.yunji.framework_template.biz.crawler.NewsContentImageCrawler;
import com.yunji.framework_template.biz.crawler.NewsCrawler;
import javassist.Modifier;
import lombok.extern.slf4j.Slf4j;

/**
 * ClassName:NewsCrawlerBeanPostProcessor <br/>
 * Date: 2018年11月30日 下午2:17:47 <br/>
 * 
 * @author fenglibin1982@163.com
 * @Blog http://blog.csdn.net/fenglibing
 * @version
 * @see
 */
@Slf4j
@Service
public class CrawlerBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        // 新闻爬虫
        if (bean instanceof NewsCrawler && !Modifier.isAbstract(bean.getClass().getModifiers())) {
            log.info("Add news crawler:" + bean.getClass().getName());
            NewsCrawler.getNewsCrawlerList().add((NewsCrawler) bean);
        }
        // 新闻内容中图片提取爬虫
        if (bean instanceof NewsContentImageCrawler && !Modifier.isAbstract(bean.getClass().getModifiers())) {
            NewsContentImageCrawler.getNewsContentImageCrawlerList().add((NewsContentImageCrawler) bean);
        }
        return bean;
    }
}
